﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace WebApp.App.Code.Cms
{
    public class Site
    {
        private static Dictionary<string,Models.Entity.Common.site> siteDic = null;
        public Site()
        {
            if (siteDic == null)
            {
                Models.DAL.Cms.Site site = new Models.DAL.Cms.Site();
                NRapid.List<Models.Entity.Common.site> sites = site.GetSite();
                siteDic = new Dictionary<string, Models.Entity.Common.site>();
                foreach (var s in sites)
                {
                    if (s.is_default != 0)
                    {
                        siteDic.Add(s.subdomain_name, s);
                    }
                    else
                    {
                        siteDic.Add("www", s);
                    }
                }
            }
        }
        public Models.Entity.Common.site GetSite(string subdomain)
        {
            if (siteDic.ContainsKey(subdomain))
            {
                return siteDic[subdomain];
            }
            else
            {
                return new Models.Entity.Common.site();
            }
        }
    }
}